package com.namazustudios.catfish;

import java.lang.annotation.Annotation;

import com.google.inject.TypeLiteral;
import com.google.inject.matcher.AbstractMatcher;
import com.google.inject.matcher.Matcher;

/**
 * Some utility matchers.
 * 
 * @author patricktwohig
 *
 */
class CatfishMatchers {

	private CatfishMatchers() {}

	public static Matcher<? super TypeLiteral<?>> 
		annotationMatcher(final Class<? extends Annotation> annotation) {
			return new AbstractMatcher<TypeLiteral<?>>() {
		
				@Override
				public boolean matches(TypeLiteral<?> type) {
					Class<?> cls = type.getRawType();
		
					do {
						if (cls.isAnnotationPresent(annotation)) {
							return true;
						}
					} while ((cls = cls.getSuperclass()) != null);
		
					return false;
		
				}
			};
	}

}
